package Hash.Easy;

import java.util.Arrays;
import java.util.function.IntUnaryOperator;

public class LC1207 {
    public boolean uniqueOccurrences(int[] arr) {
        int DELTA = 1000;
        int[] num2Occurrence = new int[2 * DELTA + 1];
        for (int num : arr)
            num2Occurrence[num + DELTA]++;
        int[] occurrence2Num = new int[DELTA + 1];
        Arrays.fill(occurrence2Num, Integer.MIN_VALUE);
        for (int i = 0; i < num2Occurrence.length; i++) {
            int occurrence = num2Occurrence[i];
            if (occurrence > 0) { // 如果数字i出现过
                if (occurrence2Num[occurrence] >= -DELTA) return false; // 存在出现次数相同的数字，返回false
                    // 不存在出现次数相同的数字，将occurrence2Num数组中下标为i出现次数的位置填成i
                else occurrence2Num[num2Occurrence[i]] = i - DELTA;
            }
        }

        return true;
    }
}
